package com.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;

import javax.servlet.http.HttpSession;

@Controller
public class LoginController {
    @GetMapping("/login")
    public String loginView() {
        return "login";
    }

    @PostMapping("/login")
    public String doLogin(String username, String password, HttpSession session) {
        if ("admin".equalsIgnoreCase(username) && "123".equalsIgnoreCase(password)) {
            session.setAttribute("username", username);
            return "index";
        } else {
            return "redirect:login";
        }
    }
}
